/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package it.polimi.deib.se2.meteocal.gui;

import it.polimi.deib.se2.meteocal.business.boundary.CalendarManager;
import it.polimi.deib.se2.meteocal.business.boundary.UserManager;
import it.polimi.deib.se2.meteocal.business.entity.User;
import javax.ejb.EJB;
import javax.inject.Named;
import javax.enterprise.context.RequestScoped;


@Named
@RequestScoped
public class EditUserBean {
    
    @EJB
    private UserManager um;
    @EJB
    private CalendarManager cl;

    private User user;
    
    public EditUserBean() {
    }
    
    public User getUser() {
        if (user == null) {
            user = um.getLoggedUser();
        }
        return user;
    }
    
    public void setUser(User user) {
        this.user=user;
    }
    
    public String edit() {
        um.edit(user);
        cl.editCalendar(user.getCalendar()); 
        return "/user/home?faces-redirect=true";
    }
}
